home *** CD-ROM | disk | FTP | other *** search
/ Windows Game Programming for Dummies (2nd Edition) / WinGamProgFD.iso / pc / DirectX SDK / DXSDK / bin / DXUtils / AppWizard / DXAppwiz.awx / TEMPLATE / D3DAPP.H < prev    next >
Encoding:
C/C++ Source or Header  |  2001-10-25  |  8.8 KB  |  209 lines

  1. //-----------------------------------------------------------------------------
  2. // File: D3DApp.h
  3. //
  4. // Desc: Application class for the Direct3D samples framework library.
  5. //-----------------------------------------------------------------------------
  6. #ifndef D3DAPP_H
  7. #define D3DAPP_H
  8.  
  9. // basetsd.h defines INT_PTR (used below).  It is not included by default
  10. // under VC 5.0.  If you are using VC6 or later, it is included via Windows.h.
  11. #include <basetsd.h> 
  12.  
  13.  
  14. //-----------------------------------------------------------------------------
  15. // Error codes
  16. //-----------------------------------------------------------------------------
  17. enum APPMSGTYPE { MSG_NONE, MSGERR_APPMUSTEXIT, MSGWARN_SWITCHEDTOREF };
  18.  
  19. #define D3DAPPERR_NODIRECT3D          0x82000001
  20. #define D3DAPPERR_NOWINDOW            0x82000002
  21. #define D3DAPPERR_NOCOMPATIBLEDEVICES 0x82000003
  22. #define D3DAPPERR_NOWINDOWABLEDEVICES 0x82000004
  23. #define D3DAPPERR_NOHARDWAREDEVICE    0x82000005
  24. #define D3DAPPERR_HALNOTCOMPATIBLE    0x82000006
  25. #define D3DAPPERR_NOWINDOWEDHAL       0x82000007
  26. #define D3DAPPERR_NODESKTOPHAL        0x82000008
  27. #define D3DAPPERR_NOHALTHISMODE       0x82000009
  28. #define D3DAPPERR_NONZEROREFCOUNT     0x8200000a
  29. #define D3DAPPERR_MEDIANOTFOUND       0x8200000b
  30. #define D3DAPPERR_RESIZEFAILED        0x8200000c
  31. #define D3DAPPERR_NULLREFDEVICE       0x8200000d
  32.  
  33.  
  34.  
  35.  
  36. //-----------------------------------------------------------------------------
  37. // Name: struct D3DModeInfo
  38. // Desc: Structure for holding information about a display mode
  39. //-----------------------------------------------------------------------------
  40. struct D3DModeInfo
  41. {
  42.     DWORD      Width;      // Screen width in this mode
  43.     DWORD      Height;     // Screen height in this mode
  44.     D3DFORMAT  Format;     // Pixel format in this mode
  45.     DWORD      dwBehavior; // Hardware / Software / Mixed vertex processing
  46.     D3DFORMAT  DepthStencilFormat; // Which depth/stencil format to use with this mode
  47. };
  48.  
  49.  
  50.  
  51.  
  52. //-----------------------------------------------------------------------------
  53. // Name: struct D3DDeviceInfo
  54. // Desc: Structure for holding information about a Direct3D device, including
  55. //       a list of modes compatible with this device
  56. //-----------------------------------------------------------------------------
  57. struct D3DDeviceInfo
  58. {
  59.     // Device data
  60.     D3DDEVTYPE   DeviceType;      // Reference, HAL, etc.
  61.     D3DCAPS8     d3dCaps;         // Capabilities of this device
  62.     const TCHAR* strDesc;         // Name of this device
  63.     BOOL         bCanDoWindowed;  // Whether this device can work in windowed mode
  64.  
  65.     // Modes for this device
  66.     DWORD        dwNumModes;
  67.     D3DModeInfo  modes[150];
  68.  
  69.     // Current state
  70.     DWORD        dwCurrentMode;
  71.     BOOL         bWindowed;
  72.     D3DMULTISAMPLE_TYPE MultiSampleTypeWindowed;
  73.     D3DMULTISAMPLE_TYPE MultiSampleTypeFullscreen;
  74. };
  75.  
  76.  
  77.  
  78.  
  79. //-----------------------------------------------------------------------------
  80. // Name: struct D3DAdapterInfo
  81. // Desc: Structure for holding information about an adapter, including a list
  82. //       of devices available on this adapter
  83. //-----------------------------------------------------------------------------
  84. struct D3DAdapterInfo
  85. {
  86.     // Adapter data
  87.     D3DADAPTER_IDENTIFIER8 d3dAdapterIdentifier;
  88.     D3DDISPLAYMODE d3ddmDesktop;      // Desktop display mode for this adapter
  89.  
  90.     // Devices for this adapter
  91.     DWORD          dwNumDevices;
  92.     D3DDeviceInfo  devices[5];
  93.  
  94.     // Current state
  95.     DWORD          dwCurrentDevice;
  96. };
  97.  
  98.  
  99.  
  100.  
  101. //-----------------------------------------------------------------------------
  102. // Name: class CD3DApplication
  103. // Desc: A base class for creating sample D3D8 applications. To create a simple
  104. //       Direct3D application, simply derive this class into a class (such as
  105. //       class CMyD3DApplication) and override the following functions, as 
  106. //       needed:
  107. //          OneTimeSceneInit()    - To initialize app data (alloc mem, etc.)
  108. //          InitDeviceObjects()   - To initialize the 3D scene objects
  109. //          FrameMove()           - To animate the scene
  110. //          Render()              - To render the scene
  111. //          DeleteDeviceObjects() - To cleanup the 3D scene objects
  112. //          FinalCleanup()        - To cleanup app data (for exitting the app)
  113. //          MsgProc()             - To handle Windows messages
  114. //-----------------------------------------------------------------------------
  115. class CD3DApplication
  116. {
  117. protected:
  118.     // Internal variables for the state of the app
  119.     D3DAdapterInfo    m_Adapters[10];
  120.     DWORD             m_dwNumAdapters;
  121.     DWORD             m_dwAdapter;
  122.     BOOL              m_bWindowed;
  123.     BOOL              m_bActive;
  124.     BOOL              m_bReady;
  125.     BOOL              m_bHasFocus;
  126.  
  127.     // Internal variables used for timing
  128.     BOOL              m_bFrameMoving;
  129.     BOOL              m_bSingleStep;
  130.  
  131.     // Internal error handling function
  132.     HRESULT DisplayErrorMsg( HRESULT hr, DWORD dwType );
  133.  
  134.     // Internal functions to manage and render the 3D scene
  135.     HRESULT BuildDeviceList();
  136.     BOOL    FindDepthStencilFormat( UINT iAdapter, D3DDEVTYPE DeviceType,
  137.                 D3DFORMAT TargetFormat, D3DFORMAT* pDepthStencilFormat );
  138.     HRESULT Initialize3DEnvironment();
  139.     HRESULT Resize3DEnvironment();
  140.     HRESULT ToggleFullscreen();
  141.     HRESULT ForceWindowed();
  142.     HRESULT UserSelectNewDevice();
  143.     VOID    Cleanup3DEnvironment();
  144.     HRESULT Render3DEnvironment();
  145.     virtual HRESULT AdjustWindowForChange();
  146.     static INT_PTR CALLBACK SelectDeviceProc( HWND hDlg, UINT msg, 
  147.                 WPARAM wParam, LPARAM lParam );
  148.  
  149. protected:
  150.     // Main objects used for creating and rendering the 3D scene
  151.     D3DPRESENT_PARAMETERS m_d3dpp;         // Parameters for CreateDevice/Reset
  152.     HWND              m_hWnd;              // The main app window
  153.     HWND              m_hWndFocus;         // The D3D focus window (usually same as m_hWnd)
  154.     LPDIRECT3D8       m_pD3D;              // The main D3D object
  155.     LPDIRECT3DDEVICE8 m_pd3dDevice;        // The D3D rendering device
  156.     D3DCAPS8          m_d3dCaps;           // Caps for the device
  157.     D3DSURFACE_DESC   m_d3dsdBackBuffer;   // Surface desc of the backbuffer
  158.     DWORD             m_dwCreateFlags;     // Indicate sw or hw vertex processing
  159.     DWORD             m_dwWindowStyle;     // Saved window style for mode switches
  160.     RECT              m_rcWindowBounds;    // Saved window bounds for mode switches
  161.     RECT              m_rcWindowClient;    // Saved client area size for mode switches
  162.  
  163.     // Variables for timing
  164.     FLOAT             m_fTime;             // Current time in seconds
  165.     FLOAT             m_fElapsedTime;      // Time elapsed since last frame
  166.     FLOAT             m_fFPS;              // Instanteous frame rate
  167.     TCHAR             m_strDeviceStats[90];// String to hold D3D device stats
  168.     TCHAR             m_strFrameStats[90]; // String to hold frame stats
  169.  
  170.     // Overridable variables for the app
  171.     TCHAR*            m_strWindowTitle;    // Title for the app's window
  172.     BOOL              m_bUseDepthBuffer;   // Whether to autocreate depthbuffer
  173.     DWORD             m_dwMinDepthBits;    // Minimum number of bits needed in depth buffer
  174.     DWORD             m_dwMinStencilBits;  // Minimum number of bits needed in stencil buffer
  175.     DWORD             m_dwCreationWidth;   // Width used to create window
  176.     DWORD             m_dwCreationHeight;  // Height used to create window
  177.     BOOL              m_bShowCursorWhenFullscreen; // Whether to show cursor when fullscreen
  178.     BOOL              m_bClipCursorWhenFullscreen; // Whether to limit cursor pos when fullscreen
  179.  
  180.     // Overridable functions for the 3D scene created by the app
  181.     virtual HRESULT ConfirmDevice(D3DCAPS8*,DWORD,D3DFORMAT)   { return S_OK; }
  182.     virtual HRESULT OneTimeSceneInit()                         { return S_OK; }
  183.     virtual HRESULT InitDeviceObjects()                        { return S_OK; }
  184.     virtual HRESULT RestoreDeviceObjects()                     { return S_OK; }
  185.     virtual HRESULT FrameMove()                                { return S_OK; }
  186.     virtual HRESULT Render()                                   { return S_OK; }
  187.     virtual HRESULT InvalidateDeviceObjects()                  { return S_OK; }
  188.     virtual HRESULT DeleteDeviceObjects()                      { return S_OK; }
  189.     virtual HRESULT FinalCleanup()                             { return S_OK; }
  190.  
  191. public:
  192.     // Functions to create, run, pause, and clean up the application
  193.     virtual HRESULT Create( HINSTANCE hInstance );
  194.     virtual INT     Run();
  195.     virtual LRESULT MsgProc( HWND hWnd, UINT uMsg, WPARAM wParam, LPARAM lParam );
  196.     virtual VOID    Pause( BOOL bPause );
  197.  
  198.     // Internal constructor
  199.     CD3DApplication();
  200. };
  201.  
  202.  
  203.  
  204.  
  205. #endif
  206.  
  207.  
  208.  
  209.